import Blockly from 'blockly/core'
import 'blockly/python_compressed'
import 'blockly/blockly_compressed'
import 'blockly/blocks_compressed'

// ceil函数模块，返回数字上入的整数
Blockly.Blocks.math_ceilkeyword = {
  init: function () {
    this.appendValueInput('ceilNumber')
      .setCheck('Number')
      .setAlign(Blockly.ALIGN_RIGHT)
      .appendField('ceil')
    this.setInputsInline(false)
    this.setOutput(true, 'Number')
    this.setColour(230)
    this.setTooltip('')
    this.setHelpUrl('')
  }
}

// 代码格式：int(statement)
Blockly.Python.math_ceilkeyword = function (block) {
  const ceilNumber = Blockly.Python.valueToCode(
    block,
    'ceilNumber',
    Blockly.Python.ORDER_NONE
  )
  Blockly.Python.definitions_.import_math = 'import math'
  const code = 'math.ceil(' + ceilNumber + ')'
  return [code, Blockly.Python.ORDER_NONE]
}

export default Blockly
